; *** Go-Moku
; *** Copyright 1998-2002 Zillions Development
; v.2.0b

; You need to purchase Zillions of Games to load this rules file
; Visit the Zillions web site at http://www.zillions-of-games.com
(translate
 ("10-line Go-Moku" "10路五子棋") ("15-line Go-Moku" "15路五子棋") ("19-line Go-Moku" "19路五子棋")
 ("19-Line Three Player Go Moku" "19路三人五子棋") ("19-Line Six-In-A-Row" "19路六子棋 - Connect6")
 ("15-line Ninuki-Renju" "15路提子连珠")("19-line Ninuki-Renju" "19路提子连珠")
 ("19-line Three Player Ninuki-Renju" "19路三人提子连珠")
)
(define add-to-empty ((verify empty?) add))

(game
    (title "10-line Go-Moku")
	(description "轮流下子，先将5个子横向、纵向或斜向连成一线者胜利。长连不算赢，但也不会算输。")
	(history "Go-Moku is an ancient game played in Japan on a Go board with Go
	   stones.  The rules apparently evolved in China over 4,000 years ago (`Wutzu`), but
	   there is evidence that they were also developed independently in ancient
	   Greece and pre-Columbian America.  This was probably the game, Kakugo (`Five Steps`
	   in Japanese), that Chinese emigrants brought to Japan c. 270 B.C. and is mentioned
	   in a work from 100 A.D.  It is written that in 1700 nearly everyone in Japan was
       playing this game.  The first book on Go-Moku (still under the name Kakugo)
	   was published in 1858.  Go-Moku was introduced into Europe in 1885.  In England
       it was called `Spoil Five` or `Go-Bang` and played on the squares rather than the
	   intersections.")
	(strategy "Play to simultaneously create two 3-in-a-rows, or a 3-in-a-row and a
       4-in-a-row, forking your opponent.  These moves are so powerful that modern Renju
       rules prohibit Black from playing them.  In fact the unrestricted form of
       Go-Moku has been proven to be a forced win for Black.\\
       The Zillions web site at <http://www.zillions-of-games.com/gomoku.html> has a
       list of good books on strategy in Go-Moku and other variants.")
    (opening-sound "Audio\\Japan1.wav")
    (win-sound "Audio\\Japan2.wav")
    (loss-sound "Audio\\Japan2.wav")
    (players Black White)
    (turn-order Black White)
    (board
        (image "images\Go-Moku\GoMokuSm.bmp")
        (grid
            (start-rectangle 20 20 52 52)
            (dimensions
				("A/B/C/D/E/F/G/H/I/J" (36 0)) ; columns
				("10/9/8/7/6/5/4/3/2/1" (0 36)) ; rows
			)
            (directions (n 0 -1) (e 1 0) (ne 1 -1) (nw -1 -1))
		)
	)
    (board-setup
        (White (stone off 200))
        (Black (stone off 200))
	)
    (piece
		(image Black "images\Go-Moku\GoStoneB32.bmp"
		       White "images\Go-Moku\GoStoneW32.bmp")
        (name stone)
		(help "Stone: drops on any empty square on the board")
        (drops (add-to-empty))
	)
    (win-condition (Black White)
	    (or (relative-config (not stone) n stone n stone n stone n stone n stone n (not stone)) 
            (relative-config (not stone) e stone e stone e stone e stone e stone e (not stone)) 
            (relative-config (not stone) ne stone ne stone ne stone ne stone ne stone ne (not stone)) 
            (relative-config (not stone) nw stone nw stone nw stone nw stone nw stone nw (not stone)) 
        )
    )
)

(variant
    (title "15-line Go-Moku")
    (default)
    (board
        (image "images\Go-Moku\GoMoku.bmp")
        (grid
            (start-rectangle 15 15 39 39)
            (dimensions
				("A/B/C/D/E/F/G/H/I/J/K/L/M/N/O" (27 0)) ; columns
				("15/14/13/12/11/10/9/8/7/6/5/4/3/2/1" (0 27))) ; rows
            (directions (n -1 0) (e 0 1) (ne -1 1) (nw -1 -1))))
    (piece
		(image Black "images\Go-Moku\GoStoneB25.bmp"
		       White "images\Go-Moku\GoStoneW25.bmp")
        (name stone)
		(help "Stone: drops on any empty square on the board")
        (drops (add-to-empty))
	)
)

(variant
    (title "19-line Go-Moku")
    (board
        (image "images\Go-Moku\GoMokulg.bmp")
        (grid
            (start-rectangle 9 9 27 27)
            (dimensions
				("A/B/C/D/E/F/G/H/I/J/K/L/M/N/O/P/Q/R/S" (18 0)) ; columns
				("19/18/17/16/15/14/13/12/11/10/9/8/7/6/5/4/3/2/1" (0 18))) ; rows
            (directions (n -1 0) (e 0 1) (ne -1 1) (nw -1 -1))))
    (piece
        (image Black "images\Go-Moku\GoStoneB17.bmp" "images\Go-Moku\GoStoneB.bmp"
               White "images\Go-Moku\GoStoneW17.bmp" "images\Go-Moku\GoStoneW.bmp")
        (name stone)
		(help "Stone: drops on any empty square on the board")
        (drops (add-to-empty))
	)
)

(variant
    (title "19-Line Three Player Go Moku")
	(history "Go-Moku is an ancient game played in Japan on a Go board with Go
	   stones.  The rules apparently evolved in China over 4,000 years ago (`Wutzu`), but
	   there is evidence that they were also developed independently in ancient
	   Greece and pre-Columbian America.  This was probably the game, Kakugo (`Five Steps`
	   in Japanese), that Chinese emigrants brought to Japan c. 270 B.C. and is mentioned
	   in a work from 100 A.D.  It is written that in 1700 nearly everyone in Japan was
       playing this game.  The first book on Go-Moku (still under the name Kakugo)
	   was published in 1858.  Go-Moku was introduced into Europe in 1885.  In England
       it was called `Spoil Five` or `Go-Bang` and played on the squares rather than the
	   intersections.\\
	   The three player variant is a more modern creation.")
    (players Black White Red)
    (turn-order Black White Red)
    (board-setup
        (White (stone off 200))
        (Black (stone off 200))
        (Red (stone off 200))
    )
    (board
        (image "images\Go-Moku\GoMokulg.bmp")
        (grid
            (start-rectangle 9 9 27 27)
            (dimensions
				("A/B/C/D/E/F/G/H/I/J/K/L/M/N/O/P/Q/R/S" (18 0)) ; columns
				("19/18/17/16/15/14/13/12/11/10/9/8/7/6/5/4/3/2/1" (0 18))) ; rows
            (directions (n -1 0) (e 0 1) (ne -1 1) (nw -1 -1)))
	)
    (piece
        (image Black "images\Go-Moku\GoStoneB17.bmp" "images\Go-Moku\GoStoneB.bmp"
               White "images\Go-Moku\GoStoneW17.bmp" "images\Go-Moku\GoStoneW.bmp"
               Red "images\Go-Moku\GoStoneR17.bmp" "images\Go-Moku\GoStoneR.bmp")
        (name stone)
        (drops (add-to-empty))
	)
    (win-condition (Black White Red)
	    (or (relative-config (not stone) n stone n stone n stone n stone n stone n (not stone)) 
            (relative-config (not stone) e stone e stone e stone e stone e stone e (not stone)) 
            (relative-config (not stone) ne stone ne stone ne stone ne stone ne stone ne (not stone)) 
            (relative-config (not stone) nw stone nw stone nw stone nw stone nw stone nw (not stone)) 
        )
    )
)

(variant
    (title "19-Line Six-In-A-Row")
    (description "胜利条件变为六子连珠。\除黑方第一手下一个子外，每回合下两个子。")
    (turn-order Black repeat White White Black Black)
    (history "本版本为台湾吴教授发明的六子棋。")
    (strategy "Try to make moves which threaten to create multiple 5 in a rows.")
    (board
        (image "images\Go-Moku\GoMokulg.bmp")
        (grid
            (start-rectangle 10 10 26 26)
            (dimensions
				("A/B/C/D/E/F/G/H/I/J/K/L/M/N/O/P/Q/R/S" (18 0)) ; columns
				("19/18/17/16/15/14/13/12/11/10/9/8/7/6/5/4/3/2/1" (0 18))) ; rows
            (directions (n -1 0) (e 0 1) (ne -1 1) (nw -1 -1)))
	)
    (win-condition (Black White)
	  	(or (relative-config stone n stone n stone n stone n stone n stone)
            (relative-config stone e stone e stone e stone e stone e stone)
            (relative-config stone ne stone ne stone ne stone ne stone ne stone)
            (relative-config stone nw stone nw stone nw stone nw stone nw stone)
		)
	)
    (piece
        (image Black "images\Go-Moku\GoStoneB17.bmp" "images\Go-Moku\GoStoneB.bmp"
               White "images\Go-Moku\GoStoneW17.bmp" "images\Go-Moku\GoStoneW.bmp")
        (name stone)
		(help "Stone: drops on any empty square on the board")
        (drops (add-to-empty))
	)
)

(variant (title "-")) ;-------------------------------------------------------------------------

(define count-caps
  (if (flag? onecap)
   Capture-10-w
   (while enemy? right)
     (if Four-capture? capture
      else
      (if Three-capture? 
        (if (flag? twocap) capture
         else (set-attribute Four-capture? true)
        )
        else
        (if Two-capture?
          (if (flag? threecap) capture else
             (if (flag? twocap) (set-attribute Four-capture? true) else
               (set-attribute Three-capture? true)
             )
          )
          else
          (if One-capture? 
            (if (flag? fourcap) capture else
              (if (flag? threecap) (set-attribute Four-capture? true) else
                (if (flag? twocap) (set-attribute Three-capture? true) else
                  (set-attribute Two-capture? true)
                )
              )
            )
	    else          
            (if (flag? fivecap) capture else
              (if (flag? fourcap) (set-attribute Four-capture? true) else
                (if (flag? threecap) (set-attribute Three-capture? true) else
                  (if (flag? twocap) (set-attribute Two-capture? true) else
                    (set-attribute One-capture? true)
                  )
                )
              )
            )
          )
        )
      )
    )
  )
)

(define bump-attribute
  (if (not-flag? onecap) (set-flag onecap true)
   else
    (if (not-flag? twocap) (set-flag twocap true)
     else
      (if (not-flag? threecap) (set-flag threecap true)
       else
       (if (not-flag? fourcap) (set-flag fourcap true)
        else (set-flag fivecap true)
       )
      )
    )
  )
)

(define check-direction
    (if (enemy? $1) ; Is there an enemy this direction?
       $1 
       (if (enemy? $1)
          $1
		  (if (friend? $1) back $1 capture $1 capture 
            (bump-attribute)
          )
       )
       back
    )
)

(define def-Capture-10
	(piece
      (name Capture-10)
      (attribute One-capture? false)
      (attribute Two-capture? false)
      (attribute Three-capture? false)
      (attribute Four-capture? false)
	)
)


(define def-stone
        (name stone)
	(help "Stone: drops on empty square, captures 2 pieces by sandwich")
        (drops (
          (verify empty?)
          mark
          (set-flag onecap false)
          (set-flag twocap false)
          (set-flag threecap false) 
          (set-flag fourcap false)
          (set-flag fivecap false)
          (check-direction n)
          (check-direction ne)
          (check-direction e)
          (check-direction se)
          (check-direction s)
          (check-direction sw)
          (check-direction w)
          (check-direction nw)
          (count-caps)
          back
          add
        ))
)

(define def-stone3
        (name stone)
	(help "Stone: drops on empty square, captures 2 pieces by sandwich")
        (image Black "images\Go-Moku\GoStoneB17.bmp" "images\Go-Moku\GoStoneB_s.bmp"
               White "images\Go-Moku\GoStoneW17.bmp" "images\Go-Moku\GoStoneW_s.bmp"
               Red "images\Go-Moku\GoStoneR17.bmp" "images\Go-Moku\GoStoneR_s.bmp")
        (drops (
          (verify empty?)
          mark
          (set-flag onecap false)
          (set-flag twocap false)
          (set-flag threecap false) 
          (set-flag fourcap false)
          (set-flag fivecap false)
          (check-direction n)
          (check-direction ne)
          (check-direction e)
          (check-direction se)
          (check-direction s)
          (check-direction sw)
          (check-direction w)
          (check-direction nw)
          (count-caps)
          back
          add
          ))
)


(define Ninuki-goals
	(or (relative-config (not stone) n stone n stone n stone n stone n stone n (not stone)) 
        (relative-config (not stone) e stone e stone e stone e stone e stone e (not stone)) 
        (relative-config (not stone) ne stone ne stone ne stone ne stone ne stone ne (not stone)) 
        (relative-config (not stone) nw stone nw stone nw stone nw stone nw stone nw (not stone))
		(pieces-remaining 0 Capture-10)
    )
)

(define def-Ninuki-text
	(description "先恰好连成五子者胜。长连无效。\
	并且，如果你下子之后恰好横、竖或斜包夹对方两个棋子，你可以提走它们。当你成功提子五次之后也算你胜利。\\两人下时，开局黑棋自动占天元。系统已经帮你走了一步，白棋开始。")
    (history "In 1899, Go-Moku players began experimenting with new restrictions designed
	   to lessen the first player's advantage and a new name `Renju` (`String of Pearls`)
       was given to the game by Chinese poetry expert, Tenry Kobayashi.  The first Renju
       federation was established in 1906 and experiments with the rules continued for the
       next 60 years.  In 1931 the third Meijin, or champion, of Japan, Yakagi Rakazan
       (who was also the Go player described in Yasunari Kawabata's `The Master of Go`)
       proposed playing on a 15x15 board instead of the 19x19 board, and this is how Renju
       is usually played today.\\
       The Ninuki-Renju variant was popular in Japan from 1900-1940 and had its own
       organization, Ninuki-Renju Sha, from 1923-1940.  In the U.S. it was marketed
       as 'Pente`, with slightly different rules, beginning in the late 1970's.  The
	   three player variant was created by Mark Lefler.")
	(strategy "Watch carefully for possibilities (for all sides) to capture pairs of
       opposing stones.   Try to combine threats to capture your opponent's stones
       with normal Go-Moku threats such as 4-in-a-rows.  The Zillions web site at
       <http://www.zillions-of-games.com/gomoku.html> has a list of good books on
       strategy in Go-Moku, Renju, and Pente.")
)

(variant
    (title "15-line Ninuki-Renju")
    (engine "Engines\Ninuki.dll")
	(def-Ninuki-text)
    (turn-order White Black)
	(board
        (image "images\Go-Moku\GoMoku.bmp")
        (grid
            (start-rectangle 15 15 39 39)
            (dimensions
				("A/B/C/D/E/F/G/H/I/J/K/L/M/N/O" (27 0)) ; columns
				("15/14/13/12/11/10/9/8/7/6/5/4/3/2/1" (0 27))) ; rows
            (directions (n 0 -1) (e 1 0) (ne 1 -1) (nw -1 -1)
			            (s 0 1)  (w -1 0) (sw -1 1) (se 1 1)
			)
		)
		(dummy Capture-10-w Capture-10-b)
        (links right (Capture-10-w Capture-10-b))	
	)
    (board-setup
        (White (stone off 200) (Capture-10 off 0 Capture-10-w))
        (Black (stone H8 off 200) (Capture-10 off 0 Capture-10-b))
    )
    (piece
        (image Black "images\Go-Moku\GoStoneB25.bmp"
               White "images\Go-Moku\GoStoneW25.bmp")
        (def-stone)
    )
    (def-Capture-10)
    (win-condition (Black White) (Ninuki-goals))
)

(variant
    (title "19-line Ninuki-Renju")
    (engine "Engines\Ninuki.dll")
	(def-Ninuki-text)
    (turn-order White Black)
 	(board
        (image "images\Go-Moku\GoMokulg.bmp")
        (grid
            (start-rectangle 9 9 27 27)
            (dimensions
				("A/B/C/D/E/F/G/H/I/J/K/L/M/N/O/P/Q/R/S" (18 0)) ; columns
				("19/18/17/16/15/14/13/12/11/10/9/8/7/6/5/4/3/2/1" (0 18))) ; rows
            (directions (n 0 -1) (e 1 0) (ne 1 -1) (nw -1 -1)
			            (s 0 1)  (w -1 0) (sw -1 1) (se 1 1)
			)
		)
		(dummy Capture-10-w Capture-10-b)
        (links right (Capture-10-w Capture-10-b))	
	)
    (board-setup
        (White (stone off 200) (Capture-10 off 0 Capture-10-w))
        (Black (stone J10 off 200) (Capture-10 off 0 Capture-10-b))
    )
    (piece
        (image Black "images\Go-Moku\GoStoneB17.bmp" "images\Go-Moku\GoStoneB.bmp"
               White "images\Go-Moku\GoStoneW17.bmp" "images\Go-Moku\GoStoneW.bmp")
        (def-stone)
    )
    (def-Capture-10)
    (win-condition (Black White) (Ninuki-goals))
)

(variant
    (title "19-line Three Player Ninuki-Renju")
	(def-Ninuki-text)
    (players Black White Red)
    (turn-order Black White Red)
    (board
        (image "images\Go-Moku\GoMokulg.bmp")
        (grid
            (start-rectangle 9 9 27 27)
            (dimensions
				("A/B/C/D/E/F/G/H/I/J/K/L/M/N/O/P/Q/R/S" (18 0)) ; columns
				("19/18/17/16/15/14/13/12/11/10/9/8/7/6/5/4/3/2/1" (0 18))) ; rows
	    (directions (n 0 -1) (e 1 0) (ne 1 -1) (nw -1 -1)
			            (s 0 1)  (w -1 0) (sw -1 1) (se 1 1)
			)
		)
		(dummy Capture-10-w Capture-10-b Capture-10-r)
		(links right (Capture-10-w Capture-10-b) (Capture-10-b Capture-10-r))	
	)

    (piece
        (def-stone3)
    )
    (def-Capture-10)
    (board-setup
       (White (stone off 200) (Capture-10 off 0 Capture-10-w))
       (Black (stone off 200) (Capture-10 off 0 Capture-10-b))
       (Red   (stone off 200) (Capture-10 off 0 Capture-10-r))
	)
	
    (win-condition (Black White Red) (Ninuki-goals))

)
